import { View } from "../../../mvc/core/View";
import { GButtonTextBar } from "../../../component/textBox/GButtonTextBar";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { EventName } from "../../mvc/EventName";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { DataEvent } from "../../events/DataEvent";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { TIllustrateVariety } from "../../../../Message/Db/Tables/TIllustrateVariety";
import { IllustrateCollectConfig } from "../../resource/IllustrateCollectConfig";
type int = number;
//class IllustrateItemList
    
    export  class IllustrateItemList extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._buttonTxtBar = new GButtonTextBar();
            this._buttonTxtBar.buttonWidth = 114;
            this._buttonTxtBar.buttonHeight = 37;
            this._buttonTxtBar.verticalGap = 2;
            this._buttonTxtBar.x = 3;
            this._buttonTxtBar.y = 0;
            this._buttonTxtBar.direction = GBoxDirection.VERTICAL;
            this._buttonTxtBar.buttonStyleName = "AchievementTabBtn";
            this._buttonTxtBar.addEventListener(EventName.GButtonTextBarChange, this.onButtonTextBarChangeHandler);
            this._buttonTxtBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onButtonSelecteChangeHandler);
            this._buttonTxtBar.maxLine = 11;
            addChild(this._buttonTxtBar);
            return;
        }

        /* internal  */onButtonTextBarChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            dispatchEvent(new DataEvent(EventName.IllustrateItemSelectChange, loc1));
            return;
        }

        /* internal  */onButtonSelecteChangeHandler(arg1: MuiEvent): void
        {
            var loc1=arg1.selectedIndex;
            var loc2=this._arrVariety[loc1];
            var loc3=this._arrIllustrate[loc1] as Array<any>;
            if (loc2 && loc2.levelLimit > Cache.instance.role.entityInfo.level) 
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(36313, loc2.levelLimit));
            }
            else if (loc3 && loc3.length <= 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(36302));
            }
            return;
        }

        public updateList(arg1: Array<any>): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=0;
            if (arg1 == null) 
            {
                return;
            }
            this._arrVariety = arg1;
            var loc1=[];
            this._arrIllustrate = [];
            var loc2=[];
            while (loc5 < arg1.length) 
            {
                loc3 = arg1[loc5] as TIllustrateVariety;
                loc4 = {"name": loc3.variety, "label": loc3.name, "value": loc3};
                loc1.push(loc4);
                loc2 = [];
                if (loc3.levelLimit <= Cache.instance.role.entityInfo.level) 
                {
                    loc2 = IllustrateCollectConfig.instance.getIllustrateByVariety(loc3.variety);
                }
                this._arrIllustrate.push(loc2);
                ++loc5;
            }
            this._buttonTxtBar.dataProvider = loc1;
            this._buttonTxtBar.textDataProvider = this._arrIllustrate;
            this._buttonTxtBar.selectedIndex = 0;
            return;
        }

        public setSelectIllustate(arg1: int, arg2: int): void
        {
            var loc2=null;
            var loc4=0;
            var loc6=0;
            if (this._buttonTxtBar.selectedIndex != (arg1 - 1)) 
            {
                this._buttonTxtBar.selectedIndex = (arg1 - 1);
            }
            var loc1=[];
            var loc3=-1;
            var loc5=0;
            while (loc5 < this._arrIllustrate.length) 
            {
                loc1 = this._arrIllustrate[loc5];
                loc6 = 0;
                while (loc6 < loc1.length) 
                {
                    if ((loc2 = loc1[loc6]) && loc2.id == arg2) 
                    {
                        loc3 = loc6;
                        break;
                    }
                    ++loc6;
                }
                if (loc3 != -1) 
                {
                    loc4 = loc5;
                    break;
                }
                ++loc5;
            }
            this._buttonTxtBar.resetBarPosition(loc4);
            this._buttonTxtBar.setTextBoxSelectedIndex(loc3);
            return;
        }

        /* internal */ /* var */_buttonTxtBar: GButtonTextBar;

        /* internal */ /* var */_arrVariety: Array<any>;

        /* internal */ /* var */_arrIllustrate: Array<any>;
    }
